//
//  BBDisplayCell.swift
//  BBetter
//
//  Created by Gmc on 2020/3/2.
//  Copyright © 2020 Gmc. All rights reserved.
//

import UIKit

class BBDisplayCell: UITableViewCell {
    open var model:BBDataModel = BBDataModel() {
        didSet {
            self.name.text = model.name
            let p = Float(self.model.numerator) / Float(self.model.denominator)
            if(p > 0 && p < 1) {
                self.tagLabel.text = "进行中"
                self.tagLabel.textColor = UIColor.colorWithHexString(hexString: "35EE77")
            } else if (p == 1) {
                self.tagLabel.text = "已完成"
                self.tagLabel.textColor = UIColor.colorWithHexString(hexString: "FF4500")
            } else {
                self.tagLabel.text = "未开始"
                self.tagLabel.textColor = UIColor.colorWithHexString(hexString: "DDDDDF")
            }
            UIView.animate(withDuration: 2) {
                self.progress.setProgress(p, animated: true)
            }
        }
    }
    private var name = UILabel()
    private var tagLabel = UILabel()
    private var progress = UIProgressView()
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initSubviews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func initSubviews() {
        name.text = "测试"
        tagLabel.text = "已完成"
        contentView.addSubview(tagLabel)
        tagLabel.snp.makeConstraints { (make) in
            make.trailing.equalTo(contentView).offset(-10)
            make.top.equalTo(contentView).offset(10)
            make.height.equalTo(20)
        }
        contentView.addSubview(name)
        name.snp.makeConstraints { (make) in
            make.leading.top.equalTo(contentView).offset(10)
            make.trailing.lessThanOrEqualTo(tagLabel.snp_leading).offset(-10)
            make.height.equalTo(20)
        }
        
//        progress.backgroundColor = .white
        progress.progressViewStyle = .default
        progress.layer.cornerRadius = 4
        progress.clipsToBounds = true
        progress.tintColor = UIColor.random()
        progress.progress = 0.00001
        contentView.addSubview(progress)
        progress.snp.makeConstraints { (make) in
            make.leading.equalTo(contentView).offset(10)
            make.bottom.trailing.equalTo(contentView).offset(-10)
            make.top.equalTo(name.snp_bottom).offset(10)
        }
        
    }
    
}
